﻿
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>计划生产工艺</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    <script src="~/X-admin/lib/layui/layui.all.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/framework/commonjs.js"></script>

</head>
<body>
    <ul lay-bar="disabled" class="mWebBanner">
        <li class="layui-nav-item" style="float:left;">
            <button id="btn-update" type="button" name="btn_update" onclick="ChanagePGY()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#xe714;</i>更换工艺
            </button>
        </li>
        <li class="layui-nav-item" style="float:left;margin-left:3%">
            <button id="btn-sync" type="button" onclick="OtherWin()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#xe63c;</i>其他工艺
            </button>
        </li>
        <li class="layui-nav-item" style="float:left;margin-left:3%">
            <button id="btn-sync" type="button" onclick="closeWin()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#x1007;</i>关闭页面
            </button>
        </li>
    </ul>
    <div class="layui-card" style="margin-top:10px">
        <div class="layui-card-body ">
            <form class="layui-form" id="mForm">
                <div class="layui-form-item" style="margin-left:3%">
                    <div class="layui-input-inline">
                        <input type="text" name="gyName" placeholder="工艺名称" class="layui-input" id="gyName" style="width:225%" readonly>
                    </div>
                    <div class="layui-input-inline" style="margin-left:40%">
                        <input type="text" name="keyCode" class="layui-input" id="keyCode" readonly>
                    </div>
                </div>
                <div class="layui-form-item" style="margin-left:3%">
                    <div class="layui-input-inline">
                        <input type="text" name="proCode" class="layui-input" id="proCode" readonly>
                    </div>

                    <div class="layui-input-inline" style="margin-left:5%">
                        <input type="text" name="versionCode" placeholder="工艺版本号" class="layui-input" id="versionCode" readonly>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block" style="margin-left:3%">
                        <input type="text" name="memo" placeholder="备注说明" class="layui-input" id="versionCode" readonly>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card" style="margin-top:6px">
        <div class="layui-card-body ">
            <div id="fDiv">
            </div>
        </div>
    </div>

</body>
</html>
<script src="~/js/framework/gongyijs.js"></script>
<script>
    var plCode = "",isRead="0",gyCode="",proCode="",proName="";
    $(function () {
        plCode = getUrlVariable("plCode");
        gyCode = getUrlVariable("gyCode");
        isRead = getUrlVariable("read");
        proCode = getUrlVariable("proCode");
        proName = getUrlVariable("proName");
        LoadPlanProcess(plCode,gyCode);
    })
    layui.use('element', function () {
        var $ = layui.jquery
            , element = layui.element; //Tab的切换功能，切换事件监听等，需要依赖element模块
        element.on('tab(gyTab)', function (data) {
            showTab = this.getAttribute('lay-id');
            $("input[name='gxCode']").val(showTab);
            loadPlanGYForm();
        });
    });
    /**
     * 加载计划工艺数据
     * **/
    function LoadPlanProcess(plCode,gyCode) {
        $.ajax({
            url: "../Plan/GetPlanProcess",
            data:{plCode:plCode,gyCode:gyCode},
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.result) {
                  var datas = rsl.data;
                  if(datas.length>0){
                       $("input[name='keyCode']").val(datas[0].gyCode);
                        $("input[name='versionCode']").val(datas[0].versionCode);
                        $("input[name='gyName']").val(datas[0].gyName);
                        $("input[name='memo']").val(datas[0].memo);
                        var pinfo = datas[0].proName+ "("+datas[0].proCode+")";
                        $("input[name='proCode']").val(pinfo);
                        proCode = datas[0].proCode;
                        PlanGx(plCode, gyCode);
                  }
                   
                }
            }
        });
    }
    function PlanGx(plCode, gyCode) {
        $.ajax({
            url: "../Plan/GetPlanGx",
            data: { plCode: plCode,gyCode:gyCode },
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.result) {
                    var datas = rsl.data;
                    if (datas.length > 0) {
                        let isEdit=true;
                        if(isRead=="1"){
                            isEdit=false
                        }
                        loadGxTab(datas, "fDiv", isEdit);
                        loadPlanGYForm();
                    }
                }
            }
        });
    }
    function loadPlanGYForm(){
        var json = {
            gxCode: showTab,
            gyCode:gyCode,
            plCode: plCode
        }
       $.ajax({
            url: "../Plan/loadPlanGxForm",
            data: { datas: JSON.stringify(json) },
           dataType: "json",
           type: "POST",
           success: function (rsl) {
            if (rsl.result) {
                InitDataForm(rsl.data,"div"+showTab);
                GetFormValue();
            } else {
                layer.msg(rsl.message);
            }
        }
    });
   }

    function GetFormValue() {
        var json = {
            gxCode: showTab,
            plCode:plCode,
            keyCode: gyCode,
        }
        $.ajax({
            url: "../ProductSet/GetStandardByCode",
            data: { datas: JSON.stringify(json) },
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.result) {
                    var sData = rsl.data;
                    SetStandardValue(sData);
                }
            }
        });

    }
    /**
     * 保存计划工艺
     * **/
    function SaveFormData(formId) {
        if(isRead=="1"){
            layer.msg("对不起，您无权限保存数据");return;
        }
        var fData = JSON.stringify(FormToJson("f" + formId));
        $.ajax({
            url: "../Plan/SavePlanProcess",
            data: { plCode: plCode,gxCode:showTab,fDatas: fData },
            dataType: "json",
            type: "POST",
            success: function (rsl) {
                if (rsl.result) {
                    layer.msg("保存成功");
                } else {
                    layer.msg(rsl.message);
                }
            }
        });
    }

    function OtherWin(){
        if (isRead == "1") {
            layer.msg("对不起，您无权限进行此操作"); return;
        }
        let gyCode = $("input[ name='keyCode']").val();
        InfoOpenPage("../ProductSet/SelectGongYi?proCode="+proCode+"&proName="+proName, "生产工艺(已选：" + gyCode + ")", "95%", "90%");
    }
    /**
     * 更换工艺 赋值
     * **/
    function ChanageGYPar(pars) {
        if (pars != undefined) {
            $("input[ name='gyName']").val(pars[0].gyName);
            $("input[ name='keyCode']").val(pars[0].keyCode);
            $("input[ name='versionCode']").val(pars[0].versionCode);
            $("input[ name='proCode']").val(pars[0].relationCode);
            $("input[ name='proCode']").val(pars[0].relationName);
            gyCode = pars[0].keyCode;
            LoadPlanProcess("", gyCode);
        }
    }
    /**
     * 计划工艺替换
     * **/
        function ChanagePGY() {
        if (isRead == "1") {
            layer.msg("对不起，您无权限进行此操作"); return;
        }
        layer.confirm('确认替换计划工艺？', function (index) {
            $.ajax({
                url: "../Plan/ChanagePlanGongYi",
                data: { plCode: plCode, gyCode: gyCode },
                dataType: "json",
                type: "POST",
                success: function (rsl) {
                    if (rsl.result) {
                        layer.msg("保存成功");
                    } else {
                        layer.msg(rsl.message);
                    }
                }
            });
        });
    }
</script>

